clear
clear matrix
clear mata
set matsize 11000
set maxvar 30000
set more off, perm
cd /Users/zachbrown/Projects/PriceTransparency/Data/
global output /Users/zachbrown/Projects/PriceTransparency/Output


// open membership dataset
guse build/members_clean.dta, clear

// Clean
gen year = floor(yearmo/100)
gen month = yearmo - year*100
gen ym = ym(year,month)
format ym %tm

drop if ym>ym(2012,1)
gen total_members=1



// Chart insurance type over time
preserve
xi i.std_product_type, noomit
collapse (sum) total_members _Istd_pro*, by(ym)

gen indem = _Istd_produ_11/total_members*100
gen ppo = indem + _Istd_produ_1/total_members*100
gen epo = ppo + _Istd_produ_8/total_members*100
gen pos = epo + _Istd_produ_2/total_members*100
gen hmo = pos + _Istd_produ_3/total_members*100

label var indem "Indemnity"
label var ppo "PPO"
label var epo "EPO"
label var pos "POS"
label var hmo "HMO"

twoway (area hmo ym, color(gs13)) ///
	(area pos ym, color(gs10)) ///
	(area epo ym, color(gs7)) ///
	(area ppo ym, color(gs5)) ///
	(area indem ym, color(gs3)), ///
	xlabel(540(12)624, tposition(inside)) /// 
	ylabel(0 (25) 100, nogrid val tposition(inside) angle(horizontal)) ///
	scheme(s1mono) ytitle("Share") xtitle("Month") ///
	graphregion(margin(r+5 l-2)) plotregion(margin(r+2 l+2)) ///
	legend(cols(5) region(lwidth(none)))
graph export $output/insurer_trends_type.pdf, replace
restore

// Chart insurance company over time
preserve
gen payer_name_abbr = payernm_short
label values payer_name_abbr payernm_short
replace payer_name_abbr = 7 if inlist(payernm_short,1,8) // Relabel Aetna and UnitedHealth as other
replace payer_name_abbr = 3 if payernm_short==4 // Relabel Connect General as Cigna
xi i.payer_name_abbr, noomit
collapse (sum) total_members _Ipayer_nam*, by(ym)

gen Other = _Ipayer_nam_7/total_members*100
gen Anthem = Other + _Ipayer_nam_2/total_members*100
gen Cigna = Anthem + _Ipayer_nam_3/total_members*100
gen Harv = Cigna + _Ipayer_nam_5/total_members*100
gen Matthew = Harv + _Ipayer_nam_6/total_members*100

label var Harv "Harvard Pilgrim "
label var Matthew "Matthew Thornton"

twoway (area Matthew ym, color(gs13)) ///
	(area Harv ym, color(gs10)) ///
	(area Cigna ym, color(gs7)) ///
	(area Anthem ym, color(gs5)) ///
	(area Other ym, color(gs3)), ///
	xlabel(540(12)624, tposition(inside)) /// 
	ylabel(0 (25) 100, nogrid val tposition(inside) angle(horizontal)) ///
	scheme(s1mono) ytitle("Share") xtitle("Month") ///
	graphregion(margin(r+5 l-2)) plotregion(margin(r+2 l+2)) ///
	legend(cols(3) region(lwidth(none)))
graph export $output/insurer_trends_payer.pdf, replace
restore




